package com.ruoyi.business.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.TServerMerInfoMapper;
import com.ruoyi.business.domain.TServerMerInfo;
import com.ruoyi.business.service.ITServerMerInfoService;
import com.ruoyi.common.core.text.Convert;

/**
 * 商户码商关系Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-02
 */
@Service
public class TServerMerInfoServiceImpl implements ITServerMerInfoService 
{
    @Autowired
    private TServerMerInfoMapper tServerMerInfoMapper;

    /**
     * 查询商户码商关系
     * 
     * @param id 商户码商关系主键
     * @return 商户码商关系
     */
    @Override
    public TServerMerInfo selectTServerMerInfoById(Long id)
    {
        return tServerMerInfoMapper.selectTServerMerInfoById(id);
    }

    /**
     * 查询商户码商关系列表
     * 
     * @param tServerMerInfo 商户码商关系
     * @return 商户码商关系
     */
    @Override
    @DataScope(userAlias = "t")
    public List<TServerMerInfo> selectTServerMerInfoList(TServerMerInfo tServerMerInfo)
    {
        return tServerMerInfoMapper.selectTServerMerInfoList(tServerMerInfo);
    }

    @Override
    public List<TServerMerInfo> selectTServerMerInfoListByNoAuth(TServerMerInfo tServerMerInfo) {
        return tServerMerInfoMapper.selectTServerMerInfoListByNoAuth(tServerMerInfo);
    }

    /**
     * 新增商户码商关系
     * 
     * @param tServerMerInfo 商户码商关系
     * @return 结果
     */
    @Override
    public int insertTServerMerInfo(TServerMerInfo tServerMerInfo)
    {
        Long[] shIds = tServerMerInfo.getShIds();
        List<TServerMerInfo> list = new ArrayList<TServerMerInfo>();
        for (Long shId : shIds)
        {
            TServerMerInfo up = new TServerMerInfo();
            up.setShId(shId);
            up.setUserId(tServerMerInfo.getUserId());
            up.setStatus(0);
            up.setCreateTime(DateUtils.getNowDate());
            list.add(up);
        }
        if (list.size() > 0)
        {
            tServerMerInfoMapper.batchServerMer(list);
        }

        return 1;
    }

    /**
     * 修改商户码商关系
     * 
     * @param tServerMerInfo 商户码商关系
     * @return 结果
     */
    @Override
    public int updateTServerMerInfo(TServerMerInfo tServerMerInfo)
    {
        tServerMerInfo.setUpdateTime(DateUtils.getNowDate());
        return tServerMerInfoMapper.updateTServerMerInfo(tServerMerInfo);
    }

    /**
     * 批量删除商户码商关系
     * 
     * @param ids 需要删除的商户码商关系主键
     * @return 结果
     */
    @Override
    public int deleteTServerMerInfoByIds(String ids)
    {
        return tServerMerInfoMapper.deleteTServerMerInfoByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除商户码商关系信息
     * 
     * @param id 商户码商关系主键
     * @return 结果
     */
    @Override
    public int deleteTServerMerInfoById(Long id)
    {
        return tServerMerInfoMapper.deleteTServerMerInfoById(id);
    }
}
